package com.lanchetech.merchant.controller;

import com.lanchetech.merchant.aop.OperatorLog;
import com.lanchetech.merchant.service.MarketingService;
import com.lanchetech.bean.request.BasePageReq;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.*;
import com.lanchetech.bean.vo.CouponVO;
import com.lanchetech.bean.vo.FlashSaleEditVO;
import com.lanchetech.bean.vo.KillActivityEditVO;
import com.lanchetech.bean.vo.PackageVO;
import com.lanchetech.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "营销管理接口", tags = "营销管理接口")
@RequestMapping("/api/marketing")
@RestController
public class MarketingController {

    @Autowired
    MarketingService marketingService;


    @ApiOperation("获取积分奖励分页")
    @PreAuthorize("hasAuthority('marketing.coin.reward')")
    @PostMapping("/getCoinRewardPage")
    public ResultData<BasePageResp<CoinRewardResp>> getCoinRewardPage(@RequestBody PageReq req) {
        return marketingService.getCoinRewardPage(req);
    }

    @OperatorLog("添加或编辑积分奖励")
    @ApiOperation("添加或编辑积分奖励")
    @PreAuthorize("hasAuthority('marketing.coin.reward.edit.auth')")
    @PostMapping("/editCoinReward")
    public BaseResp editCoinReward(@RequestBody List<CoinReward> req) {
        return marketingService.editCoinReward(req);
    }

    @OperatorLog("删除积分奖励")
    @ApiOperation("删除积分奖励")
    @PreAuthorize("hasAuthority('marketing.coin.reward.delete.auth')")
    @GetMapping("/deleteCoinReward")
    public BaseResp deleteCoinReward(@RequestParam("id") Long id) {
        return marketingService.deleteCoinReward(id);
    }

    @ApiOperation("获取积分抵扣分页")
    @PreAuthorize("hasAuthority('marketing.coin.deduction')")
    @PostMapping("/getCoinDeductionPage")
    public ResultData<BasePageResp<CoinDeductionResp>> getCoinDeductionPage(@RequestBody PageReq req) {
        return marketingService.getCoinDeductionPage(req);
    }

    @OperatorLog("添加或编辑积分抵扣")
    @ApiOperation("添加或编辑积分抵扣")
    @PreAuthorize("hasAuthority('marketing.coin.deduction.edit.auth')")
    @PostMapping("/editCoinDeduction")
    public BaseResp editCoinDeduction(@RequestBody List<CoinDeduction> req) {
        return marketingService.editCoinDeduction(req);
    }

    @OperatorLog("删除积分抵扣")
    @ApiOperation("删除积分抵扣")
    @PreAuthorize("hasAuthority('marketing.coin.deduction.delete.auth')")
    @GetMapping("/deleteCoinDeduction")
    public BaseResp deleteCoinDeduction(@RequestParam("id") Long id) {
        return marketingService.deleteCoinDeduction(id);
    }

    @OperatorLog("添加或编辑积分使用条件设置")
    @ApiOperation("添加或编辑积分使用条件设置")
    @PreAuthorize("hasAuthority('marketing.coin.coin-setting.edit.auth')")
    @PostMapping("/editCoinSetting")
    public BaseResp editCoinSetting(@RequestBody CoinSetting coinSetting) {
        return marketingService.editCoinSetting(coinSetting);
    }

    @OperatorLog("删除积分使用条件设置")
    @ApiOperation("删除积分使用条件设置")
    @PreAuthorize("hasAuthority('marketing.coin.coin-setting.edit.auth')")
    @GetMapping("/deleteCoinSetting")
    public BaseResp deleteCoinSetting(@RequestParam("id") Long id) {
        return marketingService.deleteCoinSetting(id);
    }

    @ApiOperation("获取积分使用条件分页")
    @PreAuthorize("hasAuthority('marketing.coin.coin-setting')")
    @PostMapping("/getCoinSettingPage")
    public ResultData<BasePageResp<CoinSetting>> getCoinSettingPage(@RequestBody BasePageReq req) {
        return marketingService.getCoinSettingPage(req);
    }

    @OperatorLog("编辑套餐")
    @ApiOperation("编辑套餐")
    @PreAuthorize("hasAuthority('marketing.package.package-index.edit.auth')")
    @PostMapping("/editPackage")
    public BaseResp editPackage(@RequestBody PackageVO req) {
        return marketingService.editPackage(req);
    }

    @ApiOperation("获取套餐详情")
    @PreAuthorize("hasAuthority('marketing.package.package-edit')")
    @GetMapping("/getPackageDetail")
    public ResultData<PackageResp> getPackageDetail(@RequestParam("id") Long id) {
        return marketingService.getPackageDetail(id);
    }

    @ApiOperation("获取套餐分页")
    @PreAuthorize("hasAuthority('marketing.package.package-index')")
    @PostMapping("/getPackagePage")
    public ResultData<BasePageResp<Packages>> getPackagePage(@RequestBody PageReq req) {
        return marketingService.getPackagePage(req);
    }

    @OperatorLog("删除套餐")
    @ApiOperation("删除套餐")
    @PreAuthorize("hasAuthority('marketing.package.package-edit')")
    @GetMapping("/deletePackage")
    public BaseResp deletePackage(@RequestParam("id") Long id) {
        return marketingService.deletePackage(id);
    }

    @OperatorLog("编辑优惠券")
    @ApiOperation("编辑优惠券")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index.edit.auth')")
    @PostMapping("/editCoupon")
    public BaseResp editCoupon(@RequestBody Coupon coupon) {
        return marketingService.editCoupon(coupon);
    }

    @ApiOperation("获取优惠券详情")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index.edit.auth')")
    @GetMapping("/getCouponDetail")
    public ResultData<CouponVO> getCouponDetail(@RequestParam("id") Long id) {
        return marketingService.getCouponDetail(id);
    }

    @ApiOperation("获取优惠券分页")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index')")
    @PostMapping("/getCouponPage")
    public ResultData<BasePageResp<Coupon>> getCouponPage(@RequestBody PageReq req) {
        return marketingService.getCouponPage(req);
    }

    @ApiOperation("删除优惠券")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index.edit.auth')")
    @GetMapping("/deleteCoupon")
    public BaseResp deleteCoupon(@RequestParam("id") Long id) {
        return marketingService.deleteCoupon(id);
    }
}
